package dyyx.word;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

import dyyx.CommUtil;
import dyyx.LuceneUtil;
import dyyx.file.FileHandler;
import dyyx.file.ScanContext;

public class WordFreqHandler implements FileHandler{
	
	
    private final Map<String,AtomicLong> dataMap = new HashMap<String,AtomicLong>();

	
	public void run(File file,ScanContext context)throws Exception{
		if(!file.getName().endsWith(".txt")){
			return;
		}
		// System.out.println(file.getAbsolutePath());
		String text = CommUtil.readString(file, null);
		Map<String,AtomicLong> tmp = LuceneUtil.analyzeWordFrequency(text, 2);
		LuceneUtil.merge(dataMap, tmp);
		
		System.out.println("dataMap size "+dataMap.size()+","+file);
		
	}
	
	
	public Map<String,AtomicLong> getDataMap(){
		return dataMap;
	}


}
